package cn.itsource.system.controller;

import cn.itsource.exception.BusinessException;
import cn.itsource.system.dto.LoginDto;
import cn.itsource.system.service.ILogininfoService;
import cn.itsource.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SystemController {

    @Autowired
    private ILogininfoService logininfoService;

    @PostMapping("/login")
    public JsonResult login(@RequestBody LoginDto loginDto){
        try {
            String jwtToken = logininfoService.login(loginDto);
            return JsonResult.success(jwtToken);
        } catch (BusinessException e) {
            return JsonResult.error(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error("网络繁忙，请稍后重试");
        }
    }



}
